package com.fishingwithme.infrastructure;

import com.fasterxml.jackson.databind.node.ObjectNode;
import org.json.JSONException;

public interface CodeEnum {
    int getType();

    String getName();
    String name();
    ObjectNode toJson() throws JSONException;

    // 静态方法：通过 type 查找枚举
    static <T extends CodeEnum> T ofType(Class<T> enumClass, int type) {
        for (T value : enumClass.getEnumConstants()) {
            if (value.getType() == type) {
                return value;
            }
        }
        throw new IllegalArgumentException("Unknown enum type: " + type);
    }
}
